#pragma once

#include "Itoa.h"
#include "DBPlayer.h"

struct DBRoomMember
{
	Int32	_score;
	UInt8	_pos;
	DBPlayer * _dbPlayer;

	DBRoomMember()
	{
		memset(this, 0x00, sizeof(DBRoomMember));
	}

	DBRoomMember(DBPlayer * player_, Int32 score_, UInt8 pos_)
		: _dbPlayer(player_), _score(score_), _pos(pos_)
	{}
};

struct DBRoom
{
	UInt32	_id;
	UInt32	_sid;
	UInt64	_ownerId;
	UInt32	_turn;
	UInt32	_remainTurn;
	UInt8	_huType;
	UInt8	_zx;
	UInt8	_hzlz;
	UInt8	_qxd;
	UInt8	_zn;
	UInt32	_createdTime;

	std::vector<DBRoomMember> _members;

	void updateScore(UInt64 pid, Int32 score)
	{
		for (size_t i = 0; i < _members.size(); ++i)
		{
			if (_members[i]._dbPlayer->_id == pid)
			{
				_members[i]._score = score;
				break;
			}
		}
	}

	std::string buildGamePlayer()
	{
		std::string str;
		for (size_t i = 0; i < _members.size(); ++i)
		{
			if (i > 0)
				str.append("|");
			str.append(Itoa(_members[i]._dbPlayer->_id));
			str.append(",");
			str.append(Itoa(_members[i]._score));
			str.append(",");
			str.append(Itoa(_members[i]._pos));
		}
		return str;
	}
};